public class EqualExpression extends CondAndExpression
{

	DataInfo dataInfo;

	private AddExpression addExpr;
	private int op;
	private EqualExpression eqExpr;

	public static final int EQ = 1;
	public static final int NE = 2;

	public EqualExpression()
	{

	}

	public EqualExpression( AddExpression addExpr, int op, EqualExpression eqExpr, DataInfo dataInfo )
	{
		this.addExpr = addExpr;
		this.op = op;
		this.eqExpr = eqExpr;

		this.dataInfo = dataInfo;
	}

	public String toString()
	{
		String ret = "EqualityExpression\n";

		String s = "";
		s += "| " + addExpr.toString();

		if( addExpr != null )
		{

			if( op == EQ )
				s += "| " + "==\n";
			else
				s += "| " + "!=\n";

			s += "| " + eqExpr.toString();
		}

		for( String st : s.split( "\n" ) )
			ret += "| " + st + "\n";

		return ret;
	}

	public String getType() throws SemanticException
	{

		if( eqExpr != null )
			return ("boolean");
		return (addExpr.getType());

	}

	public void check() throws SemanticException
	{

		if( eqExpr != null )
		{

			if( !eqExpr.getType().equalsIgnoreCase( addExpr.getType() ) )
			{
				String details = "The children of the equality expression do not have the same type.";
				if( dataInfo != null )
					throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
				else
					throw new SemanticException( details );

			}
			addExpr.check();
			eqExpr.check();

		}
		else
		{

			addExpr.check();

		}

	}

}